package com.supreme.secretserver.controller;

import com.alibaba.fastjson.JSONObject;
import com.supreme.commonboot.utils.AjaxResp;
import com.supreme.secretserver.annotation.Decrypt;
import com.supreme.secretserver.annotation.Encrypt;
import com.supreme.secretserver.secret.SecretParser;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping(value = "aes")
public class AESController {

    @Encrypt(type = SecretParser.AES)
    @GetMapping(value = "encrypt")
    public AjaxResp encrypt(@RequestParam(value = "message") String message) {
        return AjaxResp.instance(message);
    }

    @Decrypt(type = SecretParser.AES)
    @PostMapping(value = "decryptJson")
    public AjaxResp decryptJson(@RequestBody JSONObject bodyData) {
        return AjaxResp.instance(bodyData);
    }

    @Decrypt(type = SecretParser.AES)
    @PostMapping(value = "decryptString")
    public AjaxResp decryptString(@RequestBody String bodyData) {
        return AjaxResp.instance(bodyData);
    }

    @Decrypt(type = SecretParser.AES)
    @PostMapping(value = "decryptMap", headers = {"Content-Type", "application/x-www-form-urlencoded"})
    public AjaxResp decryptMap(@RequestBody Map<String, String> bodyData) {
        return AjaxResp.instance(bodyData);
    }
}
